<?php

namespace app\astrologer\controller\v5;

use app\astrologer\controller\AstrAuth;
use app\zyhsapi\model\ZyhsAstrLevelGradeChangeRecode;
use think\Db;
use think\exception\DbException;
use think\response\Json;

class AstrLevel extends AstrAuth
{
    /**
     * 咨询师成长等级 记录列表
     * @return Json
     * @throws DbException
     */
    public function growthList()
    {
        $zyhsAstrLevelGradeChangeRecodeModel = new ZyhsAstrLevelGradeChangeRecode();

        $data = $zyhsAstrLevelGradeChangeRecodeModel->where('astr_id', $this->astrInfo['id'])->order('create_time', 'desc')->paginate()->toArray();

        $resData = [];
        // 类型  1=>评价 2=>被申述 3=>问答回复超时  4=>问答追问回复超时 5=>连线时长 6=>被推荐
        $typeData = [
            1 => '评价',
            2 => '被申述',
            3 => '问题回复超时',
            4 => '追问回复超时',
            5 => '时长',
            6 => '被推荐',
        ];
        foreach ($data['data'] as $datum)
        {
            $title = $datum['task_type'] == 1 ? '连线' : '问答';
            $title .= '-' . $typeData[$datum['type']];
            $type = 0;
            if (in_array($datum['type'], [2, 3, 4, 5], false))
            {
                $type = $datum['task_type'];
            }
            if ($datum['task_type'] == 1)
            {   // 连线咨询
                $taskId = Db::table('good_wechat.zyhs_consult_chat_rtc_record')->where(['id' => $datum['task_id']])->value('chat_detail_id');
            } else
            {   // 问答
                $taskId = $datum['task_id'];
            }
            $resData[] = [
                'id' => (int)$taskId,
                'title' => $title,
                'create_time' => date('Y-m-d H:i:s', $datum['create_time']),
                'change' => $datum['change'] > 0 ? '+' . $datum['change'] : (string)$datum['change'],
                'type' => (int)$type,
                'app_type' => 2,
            ];
        }

        $data['data'] = $resData;

        return show(config('code.success'), '请求成功', $data);
    }
}